<extend name="Common@Layout:layui-admin" />
<block name="title">
    <title>文章列表</title>
</block>
<block name="style">
    <style>
        body {
            padding: 10px;
        }
        
        .page {
            text-align: center;
        }
        
         .yjc-hidden{
        	display:none;
        }
    </style>
</block>

<block name="main">
    <div class="my-btn-box">
        <span class="fl">
	        <a class="layui-btn btn-add btn-default " onclick="open_iframe_dialog('/admin/content/edit/group/{$_REQUEST['group']}/isadmin/1','添加文章',['100%','100%'],1)" id="btn-add-article">添加文章</a>
           
        </span>
        <input  type="hidden" id="group" value="{$_REQUEST['group']}">
		
        <span class="fr" >
<!--            <php>$_GET['cid'] ? $searchUrl = "/admin/content/index/group/".$_REQUEST['group']."/cid/".$_GET['cid'] : "/admin/content/index/group/".$_REQUEST['group'];</php>
-->            <form class="layui-form" >
               

        <div class="layui-input-inline" style="width:100px;">
            <php>
                $types = array('title' => '标题',  'author' => '作者','status' => '发布状态','id'=>'ID');
            </php>
            <select name="search_type" lay-verify="required" id="yjc-gtype" lay-filter="test">
                        <foreach name="types" item="vo" key="k">
                        <option value="{$k}" <if condition="$_GET['search_type'] eq $k ">selected</if>>{$vo}</option>
                        </foreach>
                    </select>
        </div>
        <php>
        	$yjctype =$_GET['search_type'];$kwd =$_GET['search_keyword'];
        	$a="";
        	$b="";
        	$c="";
        	$d=1;
        	if($yjctype == "id"){
        		$a =$kwd;
        	}
        	if($yjctype == "title"){
        		$b =$kwd;
        	}
        	if($yjctype == "author"){
        		$c = $kwd ;
        	}
        	if($yjctype == "status"){
        		$d = $kwd ;
        	}
        	
        	
        </php>
         <div class="layui-input-inline yjc-search-id  yjc-search <if condition='$yjctype != id'>yjc-hidden</if>" style="width:250px;">
        	
            <input type="text" name="id" data-type="id"   value="{$a}"   autocomplete="off" placeholder="请输入搜索条件" class="layui-input <if condition='$yjctype == id'>cur</if> yjc-input">
        </div>
         <div class="layui-input-inline yjc-search-title yjc-search <if condition='$yjctype&&$yjctype != title'>yjc-hidden</if>" style="width:250px;">
        	
            <input type="text" name="title" data-type="title"  value="{$b}" autocomplete="off" placeholder="请输入搜索条件" class="layui-input <if condition='!$yjctype||$yjctype == title'>cur</if> yjc-input">
        </div>
        <!--<div class="layui-input-inline yjc-search-keywords yjc-search <if condition='$yjctype != keywords'>yjc-hidden</if>" style="width:250px;">
        	
            <input type="text" name="keywords" data-type="keywords" value="{$_GET['search_keyword']}" autocomplete="off" placeholder="请输入搜索条件" class="layui-input <if condition='$yjctype == keywords'>cur</if> yjc-input">
        </div>-->
         <div class="layui-input-inline yjc-search-author yjc-search <if condition='$yjctype != author'>yjc-hidden</if>" style="width:250px;">
        	
            <input type="text" name="author " data-type="author" value="{$c}" autocomplete="off" placeholder="请输入搜索条件" class="layui-input <if condition='$yjctype == author'>cur</if> yjc-input">
        </div>
        <div class="layui-input-inline yjc-search-status yjc-search <if condition='$yjctype != status'>yjc-hidden</if>" style="width:250px;">
        	<select name="status" data-type="status" class="yjc-input <if condition='$yjctype == status'>cur</if>">
        		<option value="1" <if condition="$d ==1">selected</if>>发布</option>
        		<option value="0" <if condition="$d ==0">selected</if>>关闭</option>
        	</select>
           <!-- <input type="text" name="search_keyword" value="{$_GET['search_keyword']}" autocomplete="off" placeholder="请输入搜索条件" class="layui-input">-->
        </div>
       
       
        <a class="layui-btn mgl-20" href="javascript:;" id="yjc-sub">查询</a>
        </form>
        <?php

            $conditionStr = "";
            $strToRed = ""; 
            $condition = array();
            
            if($_GET['search_type'] && $_GET['search_keyword']){ 
            	
                $condition[$_GET['search_type']] = $_GET['search_keyword'] ;
                $strToRed = 'param-'.$_GET['search_type'].":".$_GET['search_keyword'];

            }


            $conditionStr = "condition=".condition_to_str($condition); 

            if(isset($_GET['cid'])){
                $conditionStr .= "&cid=".$_GET['cid']; 
            }
            $conditionStr .= "&group=".$_REQUEST['group'];
            //$_GET['cid'] ? $dataUrl = '/admin/content/getdata/group/'.$_REQUEST['group'].'/cid/'.$_GET['cid'] : 
            $dataUrl = '/admin/content/getdata/group/'.$_REQUEST['group'];
        ?>
            </span>

    </div>
   <!-- <div>
    	<div class="layui-btn-group" >
        <!--<if condition="!$_GET['cid'] ">
            <a href="/admin/content/index/group/{$_REQUEST['group']}" class="layui-btn">全部</a>
            <else/>
            <a href="/admin/content/index/group/{$_REQUEST['group']}" class="layui-btn layui-btn-primary">全部</a>
        </if>
        
        <volist name="cats" id="vo">
            <if condition="$_GET['cid'] eq $vo['id']">
            	
                <a href="/admin/content/index/group/{$_REQUEST['group']}/cid/{$vo.id}" class="layui-btn ">{$vo.name}</a>
                <else/>
                <a href="/admin/content/index/group/{$_REQUEST['group']}/cid/{$vo.id}" class="layui-btn layui-btn-primary ">{$vo.name}</a>
            </if>
        </volist>
    </div>	</div>-->
    <!--<div class="layui-btn-group" style="margin-left:50px;">
    	<if condition="!$_GET['status']">
            <a href="/admin/content/index/group/{$_GET['group']}/cid/{$_GET['cid']|default=0}/status/1" class="layui-btn layui-btn-primary">发布</a>
            <a href="/admin/content/index/group/{$_GET['group']}/cid/{$_GET['cid']|default=0}/status/0" class="layui-btn">关闭</a>
          	<else/>
        	<a href="/admin/content/index/group/{$_GET['group']}/cid/{$_GET['cid']|default=0}/status/1" class="layui-btn">发布</a>
            <a href="/admin/content/index/group/{$_GET['group']}/cid/{$_GET['cid']|default=0}/status/0" class="layui-btn layui-btn-primary">关闭</a>
    	</if>
    </div>-->
    <form class="delform" method="post">
        <div class="layui-form datashow" data-url="{$dataUrl}" data-to-red="{$strToRed}" data-condition="{$conditionStr}" data-p="1" data-row="10">
            <table class="layui-table">
                <colgroup>
                    <col width="50">
                    <col width="60">
                    <col>
                    <col>
                    <col>
                    <col>
                    <col width="80">
                    <col width="180">
                    <col width="180">
                    <col width="60">
                    <col width="140">
                </colgroup>
                <thead>
                    <tr>
                        <th><input type="checkbox" name="" lay-skin="primary" lay-filter="allChoose"></th>
                        <th>ID</th>
                        <th>标题</th>
                        <th>分类</th>
                        <th>作者</th>
                        <th>封面图</th>
                       
                        <th>点击量</th>
                        
                        <th>创建时间</th>
                        <th>更新时间</th>
                        <th>状态</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody class="data"></tbody>
            </table>
            <div >
           		<a class="layui-btn layui-btn-danger ajax-post confirm shuaxin" data-msg="是否确定删除选中文章?" data-url="/admin/content/del" target-form="delform" href="javascript:;" >批量删除</a>
            </div>
  <!--          <span class="layui-form-mid layui-word-aux fl" style="margin-left:10px;">注意：使用选中删除时，请先点击选中全部进行解锁！</span>-->
            <div class="page" style="margin-top:-40px"></div>
            
            <script class="data-tpl" type="text/html">
                {{# layui.each(d, function(index, item){ }}
                <tr>
                    <td>
                        <input type="checkbox" name="ids[]" value="{{item.id}}" lay-skin="primary">
                        <div class="layui-unselect layui-form-checkbox" lay-skin="primary"><i class="layui-icon"></i></div>
                    </td>
                    <td class="param-id">{{item.id}}</td>
                    <td class="param-title"><a href="/content/Article/detail/id/{{item.id}}" target="_blank">{{item.title}} </a></td>
                    <td class="paran-cats">{{item.cats}}</td>
                    <td class="param-author">{{item.author || "无"}}  </td>
                    <td class="param-fengmian"><img src="{{item.fengmian||'http://s1.ajplaychina.com/image/2017-05/2017-05-27/149587823165524(240x180).jpg'}}" style="width:50px;height:50px"></td>
                   
                    <td>{{item.click_count}}</td>
                    <td>{{item.create_time }}</td>
                    <td>{{item.update_time }}</td>
                    <td>
                        {{# if(item.status == 1){ }}发布 {{# } }} {{# if(item.status == 0){ }}关闭 {{# } }} {{# if(item.status == -1 ){ }} 禁用 {{# } }}
                    </td>
                    <td>
                        <a href="javascript:;" onclick="open_iframe_dialog('/admin/content/edit/isadmin/1/id/{{item.id}}','编辑文章',['100%','100%'],1)" class="layui-btn layui-btn-small layui-btn-normal">编辑</a>
                        <a href="javascript:;" class="layui-btn layui-btn-small layui-btn-danger mini_del" data-url="/admin/content/del/ids/{{item.id}}">删除</a>
                    </td>
                </tr>
                {{# }); }} {{# if(d.length === 0){ }} --- No Data --- {{# } }}
            </script>
        </div>
    </form>
    
</block>

<block name="script">
  
    <script>
    	var $;
    layui.use(['jquery', 'layer', 'form'], function() {
       		 $ = layui.jquery,
            layer = layui.layer,
            form = layui.form;
          
		form.on('select(test)', function(data){
			var val= data.value;
			$('.yjc-search').find('.yjc-input').removeClass('cur');
			$('.yjc-search').toggle(false);
			$('.yjc-search-'+val).show();
		 	$('.yjc-search-'+val).css({'display':'inline-block'});
		 	$('.yjc-search-'+val).find('.yjc-input').addClass('cur');
		});
		
		
		form.on('submit(*)', function(data){
			  console.log(data.elem) //被执行事件的元素DOM对象，一般为button对象
			  console.log(data.form) //被执行提交的form对象，一般在存在form标签时才会返回
			  console.log(data.field) //当前容器的全部表单字段，名值对形式：{name: value}
			  return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
			});
			
		$("#yjc-sub").click(function(){
			var gtype=$('.cur').attr('data-type');
			var keywords=$('.cur').val();
			var group=$('#group').val();
			var url = '/admin/Content/index/group/'+group;
			if(gtype&&keywords){
				url=url+'/search_type/'+gtype+'/search_keyword/'+keywords;
			}
		
			window.location.href=url;
		});
		
    });
    
    
    
  
    </script>
</block>